home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / getSelectMode.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  8.6 KB  |  306 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //
  19. //  Alias|Wavefront Script File
  20. //  MODIFY THIS AT YOUR OWN RISK
  21. //
  22. //  Creation Date:  26 June 1997
  23. //  Author:         jb
  24. //
  25. //  Description:
  26. //      This procedure figures out which selection mode the program is in.
  27. //
  28. //  Input Arguments:
  29. //        None.
  30. //
  31. //  Return Value:
  32. //        A string containing the name of the selection mode
  33. //
  34. //
  35. // ***********************************************************************
  36. //
  37. // Warning:
  38. //     Be sure that any changes made in this file are also reflected in
  39. //     setSelectMode.mel
  40. //
  41. // ***********************************************************************
  42.  
  43. global string $gAllObjects[] = {
  44.     "joint", "light", "camera", "lattice", "cluster", "sculpt", "nonlinear",
  45.     "nurbsCurve","nurbsSurface", "curveOnSurface", "polymesh", "subdiv",
  46.     "plane", "particleShape", "emitter", "field", "fluid",
  47.     "spring", "rigidBody", "rigidConstraint", "xyz", "orientationLocator",
  48.     "dimension", "texture", "locator",
  49.     "handle", "ikHandle"};
  50.  
  51. global string $gAllComponents[] = {
  52.     "controlVertex", "hull", "editPoint",//  "pv", "pe", "pfe", "pf",
  53.     // "puv", "spv", "spe", "spf", "vertex", "edge", "facet", 
  54.     "subdivMeshPoint", "subdivMeshEdge", "subdivMeshFace", "subdivMeshUV",
  55.     "curveParameterPoint", "curveKnot",
  56.     "surfaceParameterPoint", "surfaceKnot", "surfaceRange", "surfaceEdge", 
  57.     "surfaceFace", "isoparm", "latticePoint", "imagePlane",
  58.     "pr", "springComponent", "jp", "iee", "sp", "rp", "sh" 
  59.     //, "lra", "ac", "ak", "ait", "aot"
  60.     };
  61.  
  62. global string $gAnimationSelectionMasksOn[] = {"joint", "handle", "ikHandle"};
  63.  
  64. global string $gNURBSelectionMasksObjects[] = {
  65.             "nurbsCurve",
  66.             "nurbsSurface",
  67.             "curveOnSurface",
  68.             "plane",
  69.             "curve"};
  70.  
  71. global string $gNURBSelectionMasksComponents[] = {
  72.             "curveParameterPoint",
  73.             "surfaceEdge",
  74.             "isoparm",
  75.             "editPoint",
  76.             "controlVertex",
  77.             "hull",
  78.             "surfaceFace"};
  79.  
  80. global string $gDeformersSelectionMasksObjects[] = {"lattice", 
  81.             "cluster", 
  82.             "sculpt",
  83.             "nonlinear",                                                     
  84.             "nurbsCurve"};
  85.  
  86. global string $gDeformersSelectionMasksComponents[] = {"latticePoint"};
  87.  
  88. global string $gRenderingSelectionMasksObjects[] = {
  89.             "light",
  90.             "camera",
  91.             "plane"};
  92.  
  93. global string $gRenderingSelectionMasksComponents[] = {"imagePlane"};
  94.  
  95. proc int arrayFind(string $str, string $look[])
  96. // Search the array for the given string.  
  97. // Return true if found.
  98. {
  99.     int $i;
  100.  
  101.     for ($i = 0; $i < size($look); $i++) {
  102.         if ($look[$i] == $str) {
  103.             return true;
  104.         }
  105.     } 
  106.     return false;
  107. }
  108.  
  109. proc string[] pruneArray(string $main[], string $toremove[])
  110. // Remove the elements of $toremove that occur in $main and return the result
  111. {
  112.     string $result[];
  113.     int $resultSize = 0;
  114.  
  115.     int $i;
  116.  
  117.     for ($i = 0; $i < size($main); $i++) {
  118.         int $temp = arrayFind($main[$i], $toremove);
  119.         if (!$temp) {
  120. //            print("Not found " + $main[$i] +"\n");
  121.             $result[$resultSize++] = $main[$i];
  122.         }
  123.     }
  124.  
  125.     return $result;
  126. }
  127.  
  128. proc int allMasksOff(string $masks[]) 
  129. // Check to see if all of the specified selection masks are off.
  130. // Return true if they are.
  131. {
  132.     int $i;
  133.  
  134.     int $result = false;
  135.     string $cmd;
  136.  
  137. //    print ("In allMasksOff size is " + size($masks) + "\n");
  138.  
  139.     for ($i = 0; $i < size($masks) && !$result; $i++) {
  140.         $cmd = "selectType -q -" + $masks[$i] + ";";
  141.         $result = eval($cmd);
  142. //        if ($result) {
  143. //            warning ("Flag " + $masks[$i] + " is on.");
  144. //        }
  145.     }
  146.  
  147.     return !$result;
  148. }
  149.  
  150. proc int allMasksOn(string $masks[]) 
  151. // Check to see if all of the specified selection masks are on.
  152. // Return true if they are.
  153. {
  154.     int $i;
  155.  
  156.     int $result = true;
  157.     string $cmd;
  158.  
  159. //    print "In allMasksOn\n";
  160.  
  161.     for ($i = 0; $i < size($masks) && $result; $i++) {
  162.         $cmd = "selectType -q -" + $masks[$i];
  163.         $result = eval($cmd);
  164. //        if (!$result) {
  165. //            warning ("Flag " + $masks[$i] + " is off.");
  166. //        }
  167.     }
  168.  
  169.     return $result;
  170. }
  171.  
  172. proc int onlyObjectsOn(string $masks[])
  173. // Verify that only the specified object selection masks are on.
  174. {
  175.     int $i;
  176.     global string $gAllObjects[];
  177.  
  178.     string $newMaskList[] = pruneArray($gAllObjects, $masks);
  179.  
  180. //    print ("$newMaskList is of size " + size($newMaskList) + "\n");
  181.  
  182.     int $result = (allMasksOn($masks) &&
  183.                   allMasksOff($newMaskList));
  184.  
  185.     return $result;
  186. }
  187.  
  188. proc int onlyComponentsOn(string $masks[])
  189. // Verify that only the specified component selection masks are on.
  190. {
  191.     int $i;
  192.     global string $gAllComponents[];
  193.  
  194.     string $newMaskList[] = pruneArray($gAllComponents, $masks);
  195.  
  196.     int $result = (allMasksOn($masks) &&
  197.                   allMasksOff($newMaskList));
  198.  
  199.     return $result;
  200. }
  201.  
  202. global proc string getSelectMode() {
  203. //
  204. //    Return the string that represents 
  205. //  the current high level selection mask
  206. //
  207.     string $selectionModeName;
  208.     global string $gAllObjects[];
  209.     global string $gAnimationSelectionMasksOn[];
  210.     global string $gNURBSelectionMasksObjects[];
  211.     global string $gNURBSelectionMasksComponents[];
  212.     global string $gDeformersSelectionMasksObjects[];
  213.     global string $gDeformersSelectionMasksComponents[];
  214.     global string $gRenderingSelectionMasksObjects[];
  215.     global string $gRenderingSelectionMasksComponents[];
  216.     if (`selectMode -q -root` ||
  217.         `selectMode -q -leaf` ||
  218.         `selectMode -q -template`)
  219.     {
  220.         $selectionModeName = "Hierarchy";
  221.     }
  222.     else if (`selectMode -q -object`) {
  223.         if (!`selectPref -q -ignoreSelectionPriority` &&
  224.             `selectPriority -q -handle` == 5 &&
  225.             `selectPriority -q -ikHandle` == 5 &&
  226.             `selectPriority -q -joint` == 4 &&
  227.             onlyObjectsOn($gAnimationSelectionMasksOn))
  228.         {
  229.             $selectionModeName = "Animation";
  230.         }
  231.         else if (allMasksOn($gAllObjects) &&
  232.             `selectPref -q -ignoreSelectionPriority`)
  233.         {
  234.             $selectionModeName = "All Objects";    
  235.         }
  236.         else {
  237.             $selectionModeName = "Objects";    
  238.         }
  239.     } else if (`selectMode -q -component`) {
  240.         if (`selectPref -q -ignoreSelectionPriority` &&
  241.             `selectType -q -polymesh` &&
  242.             `selectType -q -subdiv` &&
  243.             `selectType -q -plane` &&
  244.             allMasksOff($gNURBSelectionMasksComponents) &&
  245.             (`selectType -q -vertex` ||
  246.             `selectType -q -edge` ||
  247.             `selectType -q -facet` ||
  248.             `selectType -q -subdivMeshPoint` ||
  249.             `selectType -q -subdivMeshEdge` ||
  250.             `selectType -q -subdivMeshFace` ||
  251.             `selectType -q -subdivMeshUV`))
  252.         {
  253.             $selectionModeName = "Polygons";    
  254.         }
  255.         else {
  256.             $selectionModeName = "Components";    
  257.         }
  258.     } else if (`selectMode -q -preset`) {
  259.         if (!`selectPref -q -ignoreSelectionPriority` &&
  260.             !`selectPref -q -allowHiliteSelection` &&
  261.             `selectPriority -q -isoparm` == 2 &&
  262.             onlyObjectsOn($gNURBSelectionMasksObjects) &&
  263.             onlyComponentsOn($gNURBSelectionMasksComponents) )
  264.         {
  265.             $selectionModeName = "NURBS";
  266.         }
  267.         else if (!`selectPref -q -ignoreSelectionPriority` &&
  268.             !`selectPref -q -allowHiliteSelection` &&
  269.             `selectPriority -q -sculpt` == 5 &&
  270.             `selectPriority -q -nonlinear` == 5 &&        
  271.             `selectPriority -q -lattice` ==  5 &&
  272.             `selectPriority -q -cluster` ==  5 &&
  273.             `selectPriority -q -locator` ==  5 &&
  274.             onlyObjectsOn($gDeformersSelectionMasksObjects) &&
  275.             onlyComponentsOn($gDeformersSelectionMasksComponents) )
  276.         {
  277.             $selectionModeName = "Deform";
  278.         }
  279.         else if (`selectPref -q -allowHiliteSelection` &&
  280.             `selectType -q -particleShape` &&
  281.             `selectType -q -emitter` &&
  282.             `selectType -q -field` &&
  283.             `selectType -q -fluid` &&
  284.             `selectType -q -collisionModel` &&
  285.             `selectType -q -spring` &&
  286.             `selectType -q -rigidBody` &&
  287.             `selectType -q -rigidConstraint` &&
  288.             `selectType -q -particle` &&
  289.             `selectType -q -springComponent` )
  290.         {
  291.             $selectionModeName = "Dynamics";
  292.         }
  293.         else if (!`selectPref -q -allowHiliteSelection` &&
  294.             onlyObjectsOn($gRenderingSelectionMasksObjects) &&
  295.             onlyComponentsOn($gRenderingSelectionMasksComponents) )
  296.         {
  297.             $selectionModeName = "Rendering";
  298.         }
  299.         else {
  300.             $selectionModeName = "Mixed";
  301.         }
  302.     }
  303.  
  304.     return $selectionModeName;
  305. }
  306.